﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using Padelcenter.Common;
using Padelcenter.DataAccess;

namespace Padelcenter.BusinessLogic.Get
{
    public class GetTarjeta : IBusinessLogic
    {
        public GetTarjeta() { }

        public void Invoke()
        {
            Tarjeta_Select oTarjetaSelect = new Tarjeta_Select();
            oTarjetaSelect.Tarjeta = this.Tarjeta;

            this.Resultset = oTarjetaSelect.Get();
        }

        public List<Tarjeta> TarjetaList()
        {
            this.Invoke();

            List<Tarjeta> listaTarjeta = new List<Tarjeta>();

            DataTable dTable = new DataTable();
            dTable = this.Resultset.Tables[0];

            if (dTable.Rows.Count > 0)
            {
                Tarjeta oTarjeta;
                foreach (DataRow r in dTable.Rows)
                {
                    oTarjeta = new Tarjeta();

                    oTarjeta.IdTarjeta = Convert.ToInt32(r["idTarjeta"]);
                    oTarjeta.Descripcion = r["Descripcion"].ToString();
                    oTarjeta.Regex = r["Regex"].ToString();

                    oTarjeta.Imagen = (byte[])r["Image"];
                    oTarjeta.FechaAlta = Convert.ToDateTime(r["FechaAlta"]);
                    oTarjeta.Activo = Convert.ToBoolean(r["Activo"]);

                    listaTarjeta.Add(oTarjeta);
                }
            }

            return listaTarjeta;
        }

        private DataSet _resultset;
        private Tarjeta _tarjeta;

        public Tarjeta Tarjeta
        {
            get { return _tarjeta; }
            set { _tarjeta = value; }
        }

        public DataSet Resultset
        {
            get { return _resultset; }
            set { _resultset = value; }
        }
    }
}
